
public class Fruit {
    private String name;
    private double price;
    private double discountRate;  // 折扣率
    private int weight;


    public Fruit(String name, double price,int weight) {
        this.name = name;
        this.price = price;
        this.discountRate = 1.0;  // 默认不打折
        this.weight = weight;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public double getPrice() {
        return price;
    }

    public void setPrice(double price) {
        this.price = price;
    }

    public double getDiscountRate() {
        return discountRate;
    }

    public void setDiscountRate(double discountRate) {
        this.discountRate = discountRate;
    }

    public int getWeight() {
        return weight;
    }

    public void setWeight(int weight) {
        this.weight = weight;
    }

    public double getTotalPrice() {
        return price*discountRate*weight;
    }

}